package com.ftg.midamall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ftg.midamall.comm.vo.CodeStatusEnum;
import com.ftg.midamall.comm.vo.RespMessUtil;
import com.ftg.midamall.entity.PmsProduct;
import com.ftg.midamall.service.IPmsProductService;
import com.ftg.midamall.service.impl.PmsProductServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author wrn
 * @since 2023-10-25
 */
@RestController
@Api(tags = "商品模块")
@RequestMapping("/pms/pmsproduct/pmsProduct")
public class PmsProductController {

    @Resource
    IPmsProductService productService;

    @GetMapping("/showAllWithPage")
    @ApiOperation("管理员查看商品信息")
    public RespMessUtil<IPage> showGoods(
            @ApiParam(value = "页码", name = "pageSize", required = true) @RequestParam(value = "pageSize", defaultValue = "1") Long pageSize,
            @ApiParam(value = "显示条数", name = "pageLimit", required = true) @RequestParam(value = "pageLimit", defaultValue = "10") Long pageLimit,
            @ApiParam(value = "商品名称", name = "name") @RequestParam(value = "name", required = false) String goodsName

    ){
        return productService.showAllWithPage(pageSize,pageLimit,goodsName);
    }

    @PostMapping("/saveGoods")
    @ApiOperation("管理员添加商品")
    public RespMessUtil<Integer> insertGoods(@RequestBody PmsProduct pp){
        Integer insertgoods = productService.insertgoods(pp);
        return insertgoods>0 ? RespMessUtil.build(CodeStatusEnum.SUCCESS,insertgoods):RespMessUtil.insertFailure();

    }

    @DeleteMapping("/deleteGoods/{id}")
    @ApiOperation("管理员删除商品")
    public RespMessUtil<Integer> deleteGoods(@ApiParam(name = "id",value = "主键",required = true) @PathVariable("id")Long id ){

        Integer deleteGoods = productService.deletegoods(id);

        return deleteGoods > 0 ? RespMessUtil.build(CodeStatusEnum.SUCCESS, deleteGoods) : RespMessUtil.deleteFailure();
    }

    @DeleteMapping("/deleteGoodsByIDS")
    @ApiOperation("管理员批量删除商品")
    public RespMessUtil<Integer> delGoodsByIds(
            @ApiParam(name = "ids",value = "主键",required = true) @RequestParam("ids")List<Long> ids){

        Integer ids1 = productService.deleteBatchByIds(ids);

        return ids1 > 0 ? RespMessUtil.build(CodeStatusEnum.SUCCESS, ids1) : RespMessUtil.deleteFailure();
    }


    @PutMapping("/modifyGoods")
    @ApiOperation("管理员修改商品")
    public RespMessUtil<Integer> updateGoods(@RequestBody PmsProduct pp){
        Integer updategoods = productService.updategoods(pp);

        return updategoods>0 ? RespMessUtil.build(CodeStatusEnum.SUCCESS,updategoods):RespMessUtil.updateFailure();

    }




}
